package com.lepu.app.fun.my;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import lib.share.utils.CallBack;
import lib.share.utils.ShareLib;

import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.app.application.MyApplication;
import com.app.utils.DateUtil;
import com.app.utils.LoginUtil;
import com.app.utils.MyNetUtil;
import com.app.utils.SdLocal;
import com.app.utils.Setting;
import com.app.utils.UmengEvent;
import com.app.utils.Utils;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.core.ApiClient;
import com.core.lib.core.AsyncRequest;
import com.core.lib.utils.main.DateUtilBase;
import com.core.lib.utils.main.LogUtilBase;
import com.core.lib.utils.main.UIHelper;
import com.core.lib.utils.main.UmengHelper;
import com.core.lib.utils.main.UtilityBase;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.core.lib.widget.CircularImageView;
import com.core.lib.widget.MyDialog;
import com.lepu.app.fun.chat.util.ChatConst;
import com.lepu.app.fun.chat.util.ChatUtil;
import com.lepu.app.fun.chat.util.LectureUtil;
import com.lepu.app.fun.my.bean.BeanMyActivityDetail;
import com.lepu.app.main.activity.AppBroswerActivity;
import com.lepu.app.main.activity.MainTabActivity;
import com.lepu.app.usercenter.bean.LoginInfo;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewRightButtonListener;
import com.lepu.pasm.R;

/**
 * 测试环境待测试
 *
 * @author wxd
 */
public class MyLectureDetailActivity extends BaseFragmentActivity implements
        OnTopbarNewLeftLayoutListener, OnTopbarNewRightButtonListener, AsyncRequest {

    private static final int GOOD_AT_CONTENT_MAX_LINES = 2;

    public static final String REQUEST_INFO = "request_info";
    public static final String REQUEST_APPLY_ACTIVITY = "request_apply_activity";
    public static final String REQUEST_CHECK_IF_CHAT = "request_check_if_chat";

    private static final String DEFAULT_TEST_GROUP_ID = "-1";

    private String mLectureID = "";

    private BeanMyActivityDetail mBeanMyActivityDetail = null;

    private ScrollView mContentScrollView = null;
    private WebView mWebView = null;

    private LinearLayout mSelectApplyLayout = null;
    private EditText mContactEditText = null;

    private int mCurrentApplyType = 0;
    private String mCover = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {

        mNeedSwipeBack = false;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_lecture_detail_activity);

        init();
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public void onResume() {
        mWebView.onResume();
        super.onResume();

        UmengHelper.onResume(this, UmengEvent.page_jiangzuo_jiangzuoxiangqing);
        requestInfo();
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public void onPause() {
        mWebView.onPause();
        super.onPause();

        UmengHelper.onPause(this, UmengEvent.page_jiangzuo_jiangzuoxiangqing);
    }

    @Override
    public void onDestroy() {

        mWebView.destroy();
        super.onDestroy();
    }

    /**
     * 添加页面动画，需要重写这个方法，
     */
    @Override
    public void onBackPressed() {
        finish(true);
    }

    @Override
    public void onTopbarLeftLayoutSelected() {
        finish(true);
    }

    @Override
    public void onTopbarRightButtonSelected() {
        share();

        //test
        //requestCheckIfChat();
    }

    /**
     * 初始化方法
     */
    @SuppressLint("SetJavaScriptEnabled")
    private void init() {
        UmengHelper.CustomEvent(this, UmengEvent.event_jiangzuo_jiangzuoxiangqing);

        // topbar
        CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
        topbar.setTopbarTitle("讲座详情");
        topbar.setonTopbarNewLeftLayoutListener(this);
        topbar.setRightText("分享");
        topbar.setOnTopbarNewRightButtonListener(this);

        Bundle data = getIntent().getExtras();
        if (data != null && data.size() > 0) {
            mLectureID = data.getString("LectureID");
            mCover = data.getString("Cover");
        }

        mContentScrollView = (ScrollView) findViewById(R.id.contentScrollView);
        mContentScrollView.setVisibility(View.GONE);

        mSelectApplyLayout = (LinearLayout) findViewById(R.id.selectApplyLayout);
        mContactEditText = (EditText) findViewById(R.id.contactEditText);

        mWebView = (WebView) findViewById(R.id.webView);
        Utils.initWebViewSettings(mWebView, true);

//        LinearLayout headIconLayout = (LinearLayout) findViewById(R.id.headIconLayout);
//        headIconLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                Intent intent = new Intent(MyLectureDetailActivity.this, MyLectureDoctorInfoActivity.class);
//                intent.putExtra("DoctorID", mBeanMyActivityDetail.DoctorID);
//                startActivity(intent, true);
//            }
//        });

    }

    /**
     * 跳入聊天
     */
    private void jumpChat() {
        //test,应该在讲座详情里跳转聊天的
        boolean flag = LoginUtil.jumpLogin(this);
        if (!flag) {
            ChatUtil.jumpChat(this, ChatConst.TYPE_ONLINE_CHAT_LECTURE, mBeanMyActivityDetail);
        }
    }

    private void share() {
        if(mBeanMyActivityDetail == null)
        {
            return;
        }

        String imgPath = SdLocal.getAppIconPath(this);
        if(!TextUtils.isEmpty(mCover))
        {
            imgPath = mCover;
        }

        String shareUrl = Setting.getShareActivityUrl(mLectureID, LoginUtil.getUserId(), LoginUtil.getLoginToken());

        // 调用官方sdk分享，可以各种形式
        ShareLib.Share(this, mBeanMyActivityDetail.ActivityName,
                mBeanMyActivityDetail.Description,
                imgPath, shareUrl, false, new CallBack() {
                    @Override
                    public void callBackSuccess(Object obj) {
                        super.callBackSuccess(obj);
                        LogUtilBase.LogD(null, "回调成功 callBackSuccess");

                        MyNetUtil.getInstance().requestShare(MyLectureDetailActivity.this, 2, mLectureID);
                    }

                    @Override
                    public void callBackFail(Object obj) {
                        super.callBackFail(obj);
                        LogUtilBase.LogD(null, "回调成功 callBackFail");
                    }
                });
    }

    public void viewClick(View view) {
        int rid = view.getId();
        switch (rid) {
            case R.id.applyButton:

                boolean flag = LoginUtil.jumpLogin(this);
                if (!flag) {
                    int status = UtilityBase.parseInt(mBeanMyActivityDetail.ActivityStatus);
                    int ActivityType = UtilityBase.parseInt(mBeanMyActivityDetail.ActivityType);

                    switch (status) {
                        case 2:

                            LoginInfo loginInfo = MyApplication.getInstance().getLoginInfo();
                            //修改昵称
                            if(LoginUtil.checkNamePhone(this, loginInfo.NickName, loginInfo.MobilePhone)){
                                showModifyNickNameDialog();
                                return;
                            }

                            if (ActivityType == 4)//电话&网络
                            {
                                if (mCurrentApplyType == 0) {

                                    String content = mContactEditText.getText().toString().trim();
                                    if (TextUtils.isEmpty(content)) {
                                        UIHelper.showToast(this, "请输入联系方式");
                                        return;
                                    }
                                    requestApplyActivity(1, content);
                                } else {
                                    requestApplyActivity(2, "");
                                }
                            } else {
                                requestApplyActivity(2, "");
                            }

                            break;
                        case 5:
                            //活动结束 网络课堂
                            if(ActivityType == 6)
                            {
                                //new add 网络课堂
                                requestCheckIfChat();
                            }
                            break;
                        case 6://进入直播 或 讲座聊天

                            if(ActivityType == 6)
                            {
                                //new add 网络课堂
                                requestCheckIfChat();
                            }else{
                                Intent intentVideo = new Intent(this, AppBroswerActivity.class);
                                intentVideo.putExtra("url", mBeanMyActivityDetail.BroadcastUrl);
                                ;
                                intentVideo.putExtra("title", "直播");
                                startActivity(intentVideo, true);
                            }
                            break;

                        default:
                            break;
                    }
                }
                break;
            case R.id.selectTypeLayout:

                showApplyType();
                break;
            default:
                break;
        }
    }

    /**
     * 选择报名方式
     */
    private void showApplyType() {
        final String[] array = getResources().getStringArray(
                R.array.array_index_lecture_detail_activity_apply_type);
        new MyDialog(this)
                .setSimpleItems(array, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        mCurrentApplyType = which;

                        if (mCurrentApplyType == 1) {
                            mContactEditText.setVisibility(View.GONE);
                        } else {
                            mContactEditText.setVisibility(View.VISIBLE);
                        }

                        String value = array[which];

                        TextView applyTypeValueTextView = (TextView) findViewById(R.id.applyTypeValueTextView);
                        applyTypeValueTextView.setText(value);
                    }
                }).create(null).show();

    }

    private void initData() {
        if (mBeanMyActivityDetail != null) {

            mContentScrollView.setVisibility(View.VISIBLE);

            if(!TextUtils.isEmpty(mBeanMyActivityDetail.Cover))
            {
                mCover = mBeanMyActivityDetail.Cover;
            }

            LinearLayout contentLayout = (LinearLayout) findViewById(R.id.contentLayout);
            int ActivityType = UtilityBase.parseInt(mBeanMyActivityDetail.ActivityType);
            if (ActivityType == 1) {
                contentLayout.setVisibility(View.GONE);
            } else {
                contentLayout.setVisibility(View.VISIBLE);

                //data
                CircularImageView doctorIconImageView = (CircularImageView) findViewById(R.id.doctorIconImageView);
                UniversalImageLoadTool.disPlay(
                        Setting.getImageUrl(mBeanMyActivityDetail.Avatar),
                        doctorIconImageView, R.drawable.app_ic_default_avatar);

                TextView titleTextView = (TextView) findViewById(R.id.titleTextView);
                TextView nameTextView = (TextView) findViewById(R.id.nameTextView);
                TextView zhiWeiTextView = (TextView) findViewById(R.id.zhiWeiTextView);
                TextView hospitalNameTextView = (TextView) findViewById(R.id.hospitalNameTextView);
                final TextView goodAtTextView = (TextView) findViewById(R.id.goodAtTextView);
                TextView lectureTimeTextView = (TextView) findViewById(R.id.lectureTimeTextView);
                TextView playTypeValueTextView = (TextView) findViewById(R.id.playTypeValueTextView);

                titleTextView.setText(mBeanMyActivityDetail.ActivityName);
                nameTextView.setText(mBeanMyActivityDetail.SpeakerName);
                zhiWeiTextView.setText(mBeanMyActivityDetail.JobTitle);
                hospitalNameTextView.setText(mBeanMyActivityDetail.CompanyName);
                lectureTimeTextView.setText(mBeanMyActivityDetail.ActivityTimeText);// 用开始时间就行了，不用拼结束时间了

                LinearLayout selectApplyLayout = (LinearLayout) findViewById(R.id.selectApplyLayout);
                TextView applyTypeValueTextView = (TextView) findViewById(R.id.applyTypeValueTextView);
                String[] typeArray = getResources().getStringArray(
                        R.array.array_index_lecture_detail_activity_type);

                final TextView goodAtZheDieTextView = (TextView) findViewById(R.id.goodAtZheDieTextView);
                goodAtZheDieTextView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int tag = (int) v.getTag();
                        if (tag == 0) {
                            goodAtTextView.setEllipsize(null); // 展开
                            goodAtTextView.setSingleLine(false);

                            goodAtZheDieTextView.setTag(1);
                            goodAtZheDieTextView.setText("收起");
                            Drawable drawable = getResources().getDrawable(R.drawable.my_lecture_detail_goodat_up);
                            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//必须设置图片大小，否则不显示
                            goodAtZheDieTextView.setCompoundDrawables(null,null,drawable,null);

                        } else {
                            goodAtTextView
                                    .setEllipsize(TextUtils.TruncateAt.END); // 收缩
                            goodAtTextView.setLines(GOOD_AT_CONTENT_MAX_LINES);

                            goodAtZheDieTextView.setTag(0);
                            goodAtZheDieTextView.setText("展开");
                            Drawable drawable = getResources().getDrawable(R.drawable.my_lecture_detail_goodat_down);
                            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//必须设置图片大小，否则不显示
                            goodAtZheDieTextView.setCompoundDrawables(null, null, drawable, null);
                        }
                    }
                });

                //刷新 当前页面，这个控件不刷新
                String goodAtText = goodAtTextView.getText().toString().trim();
                if(TextUtils.isEmpty(goodAtText))
                {
                    final String resume = mBeanMyActivityDetail.Resume;
//               final String resume = "test测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试" +
//                        "测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试" +
//                        "测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试";
                    goodAtTextView.setText(resume);
                    ViewTreeObserver observer = goodAtTextView.getViewTreeObserver();
                    observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                        public void onGlobalLayout() {
                            ViewTreeObserver obs = goodAtTextView.getViewTreeObserver();
                            obs.removeGlobalOnLayoutListener(this);
                            if (goodAtTextView.getLineCount() > GOOD_AT_CONTENT_MAX_LINES) {
                                goodAtZheDieTextView.setVisibility(View.VISIBLE);
                                goodAtTextView.setEllipsize(TextUtils.TruncateAt.END); // 收缩
                                goodAtTextView.setLines(GOOD_AT_CONTENT_MAX_LINES);

                                goodAtZheDieTextView.setTag(0);

                                try {
                                    if (!TextUtils.isEmpty(resume) && resume.length() > 10) {
                                        int lineEndIndex = goodAtTextView.getLayout().getLineEnd(GOOD_AT_CONTENT_MAX_LINES - 1);
                                        if (lineEndIndex > 3) {
                                            String text = resume.subSequence(0, lineEndIndex - 3) + "...";
                                            goodAtTextView.setText(text);
                                        }
                                    }
                                } catch (Exception ex) {
                                }
                            } else {
                                goodAtZheDieTextView.setVisibility(View.GONE);
                            }
                        }
                    });
                }

                if (ActivityType > 0) {
                    if (ActivityType == 4) {
                        playTypeValueTextView.setText("电话&网络");
                        applyTypeValueTextView.setText("电话&网络");
                        selectApplyLayout.setVisibility(View.VISIBLE);
                    } else {
                        try
                        {
                            playTypeValueTextView.setText(typeArray[ActivityType - 1]);
                        }catch (Exception e){
                            playTypeValueTextView.setText("");
                        }

                        selectApplyLayout.setVisibility(View.GONE);
                    }
                } else {
                    playTypeValueTextView.setText("无");
                    selectApplyLayout.setVisibility(View.GONE);
                }

                updateApplyActivityStatus();
            }

            mWebView.loadData(mBeanMyActivityDetail.Content,
                    "text/html; charset=UTF-8", null);
        }
    }

    private void updateApplyActivityStatus() {

        LinearLayout selectTypeLayout = (LinearLayout) findViewById(R.id.selectTypeLayout);
        Button applyButton = (Button) findViewById(R.id.applyButton);
        if(!LoginUtil.checkIsLogin()){
            applyButton.setText("请先登录");
            return;
        }

        int state = UtilityBase.parseInt(mBeanMyActivityDetail.ActivityStatus);
        int ActivityType = UtilityBase.parseInt(mBeanMyActivityDetail.ActivityType);

        switch (state) {
            case 1:
                applyButton.setText("即将开始");
                applyButton.setClickable(false);

                selectTypeLayout.setEnabled(false);
                break;
            case 2:
                applyButton.setText("立刻报名");//==========================

                selectTypeLayout.setEnabled(true);
                break;
            case 3:
                applyButton.setText("报名结束");

                applyButton.setEnabled(false);
                selectTypeLayout.setEnabled(false);
                break;
            case 4:
                applyButton.setText("已报名");

                //applyButton.setEnabled(false);
                selectTypeLayout.setEnabled(false);
                break;
            case 5:
                //活动结束
                int IsGroupMember = UtilityBase.parseInt(mBeanMyActivityDetail.IsGroupMember);
                if (ActivityType == 6 && IsGroupMember == 1)
                {
                    //网络课堂
                    applyButton.setText("查看讲座");

                    applyButton.setEnabled(true);
                    selectTypeLayout.setEnabled(false);
                }else{
                    applyButton.setText("活动结束");

                    applyButton.setEnabled(false);
                    selectTypeLayout.setEnabled(false);
                }
                break;
            case 6:
                if (ActivityType == 6)
                {
                    //网络课堂
                    applyButton.setText("进入讲座");
                }else{
                    applyButton.setText("进入直播");
                }
                selectTypeLayout.setEnabled(false);

                break;
            case 7:
                applyButton.setText("报名成功");

                //applyButton.setEnabled(false);
                selectTypeLayout.setEnabled(false);
                break;

            default:
                break;
        }
    }

    /**
     * 获取讲座详情
     */
    public void requestInfo() {

        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject();

        try {
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());

            params.put("ActivityID", mLectureID);// 活动ID

        } catch (Exception e) {
        }
        map.put("ht", params);

        showProgressDialog();
        ApiClient.http_post_main(Setting.getActivityDetailUrl(), map, null,
                this, REQUEST_INFO, false);
    }

    /**
     * 检查是否可以进入聊天
     */
    private void requestCheckIfChat() {

        boolean flag = LoginUtil.jumpLogin(this);
        if (flag) {
            return;
        }

        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject();

        try {
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());

            String GroupID = DEFAULT_TEST_GROUP_ID;
            if(!TextUtils.isEmpty(mBeanMyActivityDetail.ChatGroupID))
            {
                GroupID = mBeanMyActivityDetail.ChatGroupID;
            }
            params.put("GroupID", GroupID);// 活动ID

        } catch (Exception e) {
        }
        map.put("ht", params);

        showProgressDialog();
        ApiClient.http_post_main(Setting.getActivityGoChatUrl(), map, null,
                this, REQUEST_CHECK_IF_CHAT, true);
    }

    private void requestApplyActivity(int ContactType, String ContactPhone) {

        Map<String, Object> map = new HashMap<String, Object>();
        JSONObject params = new JSONObject();

        try {
            params.put("DeviceID", Setting.DEVICEID);
            params.put("ApplicationID", Setting.APPLICATIONID);

            params.put("UserID", LoginUtil.getUserId());
            params.put("LoginToken", LoginUtil.getLoginToken());

            params.put("ActivityID", mLectureID);// 活动ID
            params.put("ContactType", ContactType);// 联系类型 1：电话 2：网络
            params.put("ContactPhone", ContactPhone);// 联系电话

        } catch (Exception e) {
        }
        map.put("ht", params);

        showProgressDialog();
        ApiClient.http_post_main(Setting.getUserApplyActivityUrl(), map, null,
                this, REQUEST_APPLY_ACTIVITY, false);
    }

    private void showRemoveLectureChatDialog() {
        MyDialog dialog = new MyDialog(this)
                .setMessage("抱歉，管理员已将您移除讲座群。")
                .setNegativeButtonSplitImageHide(true)
                .setPositiveButton(R.string.app_ok,
                        new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {

                            }
                        });

        dialog.create(null);
        dialog.showMyDialog();
    }

    private void showScroeNotDialog() {
        MyDialog dialog = new MyDialog(this)
                .setMessage("积分不足无法报名。")
                .setNegativeButtonSplitImageHide(true)
                .setPositiveButton(R.string.app_ok,
                        new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {

                            }
                        });

        dialog.create(null);
        dialog.showMyDialog();
    }

    private void showModifyNickNameDialog() {
        MyDialog dialog = new MyDialog(this)
                .setMessage("请您先设置昵称，再报名参加网络课堂（讲座群聊）。")
                .setNegativeButton(R.string.lecture_chat_no_set_nickname, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                })
                .setPositiveButton(R.string.lecture_chat_yes_set_nickname,
                        new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                Intent intent = new Intent(MyLectureDetailActivity.this, MyUserModifyNameActivity.class);
                                startActivity(intent, true);
                            }
                        });

        dialog.create(null);
        dialog.showMyDialog();
    }

    private void dowithCheckIfChat(String data)
    {
        try {
            JSONObject jsonObject = new JSONObject(data);
            JSONObject obj1 = (JSONObject) jsonObject.get("Result");
            JSONObject obj2 = (JSONObject) obj1.get("DetailInfo");

            String IsGroupMember = obj2.optString("IsGroupMember");
            String UserRank = obj2.optString("UserRank");

            //IsGroupMember = "1";//是否是群成员
            //UserRank = "2";//是否可以发语音，讲座人，普通用户
            if(IsGroupMember.equals("1"))
            {
                int ActivityType = UtilityBase.parseInt(mBeanMyActivityDetail.ActivityType);
                int ActivityStatus = UtilityBase.parseInt(mBeanMyActivityDetail.ActivityStatus);

                if (ActivityType == 6 && ActivityStatus == 5) {
                    //活动结束，并且类型为网络课堂  只能看聊天记录，不能聊天
                    mBeanMyActivityDetail.IfCanChat = "0";
                } else {
                    mBeanMyActivityDetail.IfCanChat = "1";//是否可以聊天
                }
                //mBeanMyActivityDetail.IfCanChat = "1";//test remove

                mBeanMyActivityDetail.IsGroupMember = IsGroupMember;
                mBeanMyActivityDetail.UserRank = UserRank;

                String GroupID = DEFAULT_TEST_GROUP_ID;
                if(!TextUtils.isEmpty(mBeanMyActivityDetail.ChatGroupID))
                {
                    GroupID = mBeanMyActivityDetail.ChatGroupID;
                }
                mBeanMyActivityDetail.ChatGroupID = GroupID;

                LectureUtil.getInstance().requestAllGroupInfo(this, GroupID, new com.core.lib.utils.CallBack() {
                    @Override
                    public void callBackSuccess(Object obj) {
                        super.callBackSuccess(obj);

                        hideProgressDialog();

                        //进入聊天
                        jumpChat();
                    }

                    @Override
                    public void callBackFail(Object obj) {
                        super.callBackFail(obj);

                        hideProgressDialog();
                    }
                });
            }else{
                hideProgressDialog();
                showRemoveLectureChatDialog();
            }
        } catch (JSONException e) {
            e.printStackTrace();
            hideProgressDialog();
        }
    }

    @Override
    public void RequestComplete(Object object, Object data) {
        if (object.equals(REQUEST_INFO)) {

            hideProgressDialog();

            mBeanMyActivityDetail = BeanMyActivityDetail
                    .parseDetailInfo((String) data);
            initData();
        } else if (object.equals(REQUEST_APPLY_ACTIVITY)) {
            hideProgressDialog();

            mBeanMyActivityDetail.ActivityStatus = "4";
            updateApplyActivityStatus();
        } else if (object.equals(REQUEST_CHECK_IF_CHAT)) {

            dowithCheckIfChat((String)data);
        }
    }

    @Override
    public void RequestError(Object object, int errorId, String data) {
        if (object.equals(REQUEST_INFO)) {

            hideProgressDialog();

        } else if (object.equals(REQUEST_APPLY_ACTIVITY)) {
            hideProgressDialog();

            String result = (String) data;
            int code = 0;
            try {
                JSONObject jsonObject = new JSONObject(result);
                JSONObject obj1 = (JSONObject) jsonObject.get("Result");
                code = obj1.optInt("Status");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            if(code == 1101){
                showScroeNotDialog();
            }
        } else if (object.equals(REQUEST_CHECK_IF_CHAT)) {
            hideProgressDialog();
        }
    }
}
